﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraEditors;
using ECRMS.WinForm.BaseClass.Other;
using System.Drawing;
using DevExpress.XtraTreeList;
using System.Windows.Forms;

namespace ECRMS.WinForm.BaseClass.Common
{
    public class CommonClass
    {
        public Guid GetGridFocusRowRefId(GridControl grid,GridView view,  string fieldName )
        {
            ColumnView cv = (ColumnView)grid.FocusedView;
            int focusedhandle = cv.FocusedRowHandle;
            object rowIdObj = view.GetRowCellValue(focusedhandle, fieldName);
            if ( rowIdObj!=null)
            {
                return (Guid)(rowIdObj);
            }
            else
            {
                return Guid.Empty;
            }
        }
        //根据键得到某个combox的index
        public int GetComboxIndex(ComboBoxEdit combox,Guid value)
        {
            foreach (var item in combox.Properties.Items)
            {
                ComboxData data = item as ComboxData;
                if (data.GuidValue == value)
                {
                    return combox.Properties.Items.IndexOf(item);
                }
            }
            return -1;
        }


        public Guid GetTreeKeyValue(TreeList treeList, string fieldName)
        {

            if (treeList.FocusedNode != null)
            {
                return new Guid( treeList.FocusedNode[fieldName].ToString());
            }
            else
            {
                return Guid.Empty;
            }
        }

    }
}
